const mongoose = require("mongoose");
const {connection} = require("mongoose");
class Db{
	constructor(model) {
		this.model = model;
	}
	connection(){
		if(mongoose.connection.readyState === 1) return Promise.resolve();
		return mongoose.connect("mongodb://127.0.0.1/weibo",{
			serverSelectionTimeoutMS:10000
		});
	}
	// 插入一条记录
	// insertObj:插入的对象（文档）
	async insertOne(insertObj){
		await connection();
		return this.model(insertObj).save();
	}
}
module.exports = Db;